//
//  LZCouponManagerCouponDetailViewController.m
//  laziz_Merchant
//
//  Created by xbnzd on 16/12/20.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZCouponManagerCouponDetailViewController.h"
#import "UITableView+FDTemplateLayoutCell.h"
#import "LZCouponDetailTopCell.h"
#import "LZGrabCouponDetailRulesOfUseCell.h"
#import "LZGrabCouponDetailMealsTimeCell.h"
#import "LZCouponListModel.h"
#import "LZDateFormatterManager.h"

static NSString *kTopCell = @"topcell";
static NSString *kRulesCell = @"ruleCell";
static NSString *kMealsCell = @"mealscell";

@interface LZCouponManagerCouponDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation LZCouponManagerCouponDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.umLogPageViewName = @"优惠管理-优惠劵详情页面";
    [self configureUI];
}

#pragma mark -
#pragma mark configure UI
- (void)configureUI
{
    self.title = LZLocalizedString(@"coupon_details", nil);
    [self.tableView registerNib:[UINib nibWithNibName:@"LZCouponDetailTopCell" bundle:nil] forCellReuseIdentifier:kTopCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZGrabCouponDetailRulesOfUseCell" bundle:nil] forCellReuseIdentifier:kRulesCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZGrabCouponDetailMealsTimeCell" bundle:nil] forCellReuseIdentifier:kMealsCell];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

#pragma mark -
#pragma mark tableview delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WS(wSelf);
    switch (indexPath.row) {
        case 0:
            return [tableView fd_heightForCellWithIdentifier:kTopCell configuration:^(id cell) {
                LZCouponDetailTopCell *cellTemp = (LZCouponDetailTopCell *)cell;
                [cellTemp loadContentWithData:wSelf.dataModel];
            }];
            break;
        case 1:
            return [tableView fd_heightForCellWithIdentifier:kRulesCell configuration:^(id cell) {
                LZGrabCouponDetailRulesOfUseCell *cellTemp = (LZGrabCouponDetailRulesOfUseCell *)cell;
                [cellTemp loadTitle:LZLocalizedString(@"group_terms_of_use", nil) contentStr:wSelf.dataModel.couponsUseConditions guizeContent:wSelf.dataModel.couponsRemindRule];
            }];
            break;
        case 2:
            return [tableView fd_heightForCellWithIdentifier:kMealsCell configuration:^(id cell) {
                LZGrabCouponDetailMealsTimeCell *cellTemp = (LZGrabCouponDetailMealsTimeCell *)cell;
                NSString *everyDayValid = [wSelf.dataModel getCouponEverydayValid];

                [cellTemp loadCouponValidityPeriod:[NSString stringWithFormat:@"%@ - %@",[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.dataModel.couponsStartTime],[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.dataModel.couponsEndTime]] ValidExcept:wSelf.dataModel.couponsExceptTime EverydayValid:everyDayValid otherContent:wSelf.dataModel.couponsRemindAppoint];
                
            }];
            break;
            
        default:
            break;
    }
    
    return 0;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:{
            LZCouponDetailTopCell *cell = [tableView dequeueReusableCellWithIdentifier:kTopCell];
            [cell loadContentWithData:self.dataModel];
            
            return cell;
        }
            
            break;
        case 1:{
            LZGrabCouponDetailRulesOfUseCell *cell = [tableView dequeueReusableCellWithIdentifier:kRulesCell];
            [cell loadTitle:LZLocalizedString(@"group_terms_of_use", nil) contentStr:self.dataModel.couponsUseConditions guizeContent:self.dataModel.couponsRemindRule];
            
            return cell;
        }
            
            break;
        case 2:{
            LZGrabCouponDetailMealsTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:kMealsCell];
            NSString *everyDayValid = [self.dataModel getCouponEverydayValid];

            [cell loadCouponValidityPeriod:[NSString stringWithFormat:@"%@ - %@",[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.couponsStartTime],[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.couponsEndTime]] ValidExcept:self.dataModel.couponsExceptTime EverydayValid:everyDayValid otherContent:self.dataModel.couponsRemindAppoint];
            
            return cell;
        }
            
            break;
        default:
            break;
    }
    
    return nil;


}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end
